﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="taskMsgReceiveObject.aspx.cs" Inherits="ZX.WebApp.EHR.taskMsgReceiveObject" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>接收对象设置</title>
    <link href="../Styles/table_style.css" rel="stylesheet" type="text/css" />
    <script src="../Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/yahoo-dom-event/yahoo-dom-event.js"></script>
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/json/json-min.js"></script>
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/connection/connection-min.js"></script>
     <script type="text/javascript" src="../Scripts/Jquery.form.js"></script>
     <script type="text/javascript" src="../Scripts/CombinButton.js"></script>
    <script type="text/javascript">
    // <![CDATA[
        $(document).ready(function () {
            addtr();
            //全选,全不选
            $("#chkAll").click(function () {
                //遍历tr
                //alert($("#chkAll").attr("checked"));
                if ($("#chkAll").attr("checked")) {
                    //全选
                    $("#tbEmp tr").first().nextAll().each(function () {
                        $(this).addClass("selectedTr").find(":checkbox").attr("checked", true);
                    });
                }
                else {
                    //全不选
                    $("#tbEmp tr").first().nextAll().each(function () {
                        $(this).removeClass("selectedTr").find(":checkbox").attr("checked", false);
                    });
                }
            });

            //确定按钮
            var strJson = "{\"ReceiveObject\":[";
            parent.$("#okay").mousedown(function () {
                //遍历tr
                var $trs = $("#tbEmp").find("tr");
                for (var i = 2; i < $trs.length; i++) {
                    var $tr = $trs.eq(i);
                    if ($tr.hasClass("selectedTr")) {
                        var EmployeeID = $tr.find("input[name=EmployeeID]").val();
                        var EmpName = $tr.find("input[name=txtEmployeeID]").val();
                        var EmployeeCode = $tr.find("input[name=EmployeeCode]").val();
                        var PhoneNo = $tr.find("input[name=PhoneNo]").val();
                        var EMail = $tr.find("input[name=EMail]").val();
                        strJson += "{\"EmployeeID\":'" + EmployeeID + "\",\"EmpName':\"" + EmpName + "\",\"EmployeeCode\":\"" + EmployeeCode + "\",\"PhoneNo\":\"" + PhoneNo+ "\",\"EMail\":\"" + EMail+"\"},";
                    }
                }
                strJson = strJson.substr(0, strJson.length - 1);
                strJson += "]}";
                parent.taskMsgReceiveObject = strJson;
            });

        });


        //选择员工
        var employeeId;
        var ValueChanged = function (rowobj) {
            employeeId = $("#empId").val();
        }

        var TextChanged = function (rowobj) {
            var employeeName = $("#txtempId").val();
            if (employeeId == "" || employeeId == "undefined") {
                return;
            }
            if (employeeName == "" || employeeName == "undefined") {
                return;
            }
            //debugger
            $("#txtEmployeeID", rowobj).val(employeeName);
            $("#EmployeeID", rowobj).val(employeeId);
            GetEmpInfoByEmpID(employeeId);
        }

        //获取员工所属部门名称
        function GetEmpInfoByEmpID(empId) {
            var url = "../Extend/AjaxData/jsonlist.aspx?entity=V_hrEmployee&condition=ID='" + empId + "'";
            $.get(url, function (d, s) {
                var list = eval("(" + d + ")");
                for (var o in list.rows) {
                    var t = list.rows[o].DeptName;
                    if (typeof (t) != "undefined") {
                        $("#DeptName", rowobj).val(t);
                        $("#PostName", rowobj).val(list.rows[o].PostName);
                        $("#EmployeeCode", rowobj).val(list.rows[o].EmployeeCode);
                        $("#PhoneNo", rowobj).val(list.rows[o].PhoneNo);
                        $("#EMail", rowobj).val(list.rows[o].Email);
                    }
                }
            });
        }


        //增加行
        function addtr() {
            var tr = $("#tbEmp tr").eq(1).clone();
            tr.show();
            tr.appendTo("#tbEmp").removeClass("selectedTr").find(":checkbox").attr("checked", false);
            var EmpName = $("input[name=txtEmployeeID]:last");
            var EmployeeCode = $("input[name=EmployeeCode]:last");
            var DeptName = $("input[name=DeptName]:last");
            var PostName = $("input[name=PostName]:last");
            var PhoneNo = $("input[name=PhoneNo]:last");
            var EMail = $("input[name=EMail]:last");

            EmpName.attr("readonly", "readonly");
            EmpName.css("background", "whitesmoke");
            EmployeeCode.attr("readonly", "readonly");
            EmployeeCode.css("background", "whitesmoke");
            DeptName.attr("readonly", "readonly");
            DeptName.css("background", "whitesmoke");
            PostName.attr("readonly", "readonly");
            PostName.css("background", "whitesmoke");

        }

        //删除行
        function deltr() {
            //遍历tr
            $("#tbEmp tr").first().nextAll().each(function () {
                if ($(this).hasClass("selectedTr")) {
                    $(this).remove();
                }
            });
        };

        //选中行
        $("#tbEmp tr").live("click", function () {
            if ($(this).hasClass("selectedTr")) {
                $(this).removeClass("selectedTr").find(":checkbox").attr("checked", false);
                $("#chkAll").attr("checked", false);

            } 
            else {
                $(this).addClass("selectedTr").find(":checkbox").attr("checked", true);
                var ischkAll = true;
                $("#tbEmp tr").first().nextAll().each(function () {
                    if (!$(this).hasClass("selectedTr")) {
                        ischkAll = false;
                    }
                });
                if (ischkAll) {
                    $("#chkAll").attr("checked", true);
                }
            }
        });

    // ]]> 
     </script>
     <style type="text/css">
    body{font-family: 宋体, Arial, Helvetica, sans-serif;font-size: 12px;color: #333333;background-color: #FFFFFF;} 
    select{width:99%;} td { border: 1px solid #CCCCCC;}
    .textarea{ width: 96%;height: 25px;}	
   .selectedTr{  background-color: blue;} 
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <input id="empId" name="empId" type="hidden" /> <input id="txtempId" name="txtempId" type="hidden" />
    <div id="divBtn">
        <input type="button" id="btnADD" value="新增" onclick="addtr();" />
        <input type="button" id="btnDEL" value="删除" onclick="deltr();" />
    </div>
    <table align="center" border="1" id="tbEmp" name="tbEmp" style="border-collapse: collapse" width="99%">
        <tr id="data_head" style="background-color: #e4e7e2">
           <td style="text-align: center"><input type="checkbox" id="chkAll" name="chkAll"/></td>
	        <td style="text-align: center">员工姓名</td>
	        <td style="text-align: center">员工编号</td>
	        <td style="text-align: center;display:none">部门</td>
	        <td style="text-align: center;display:none"> 岗位</td>
	        <td style="text-align: center">手机号</td>
	        <td style="text-align: center"> EMAIL</td>

        </tr>
        <tr style="display:none">
            <td>
                <input type="checkbox" id="chktr" name="chktr" />
            </td>
	        <td>
		        <input  id="EmployeeID" name="EmployeeID" type="hidden" value="" />
                <input  id="txtEmployeeID" name="txtEmployeeID" style="border-bottom-style: none; border-bottom-color: transparent; border-right-style: none; border-top-color: transparent; border-top-style: none; border-right-color: transparent; border-left-style: none; border-left-color: transparent" type="text" />
                <button id="btnempId" name="emp" onclick="SelectEmployee(this);" type="button">选择</button>
            </td>
	        <td>
		        <input  id="EmployeeCode" name="EmployeeCode" style="border-bottom-style: none; border-bottom-color: transparent; border-right-style: none; border-top-color: transparent; border-top-style: none; border-right-color: transparent; border-left-style: none; border-left-color: transparent" type="text" />
            </td>
	        <td style="display:none">
		        <input id="DeptName" name="DeptName"  style="border-bottom-style: none; border-bottom-color: transparent; border-right-style: none; border-top-color: transparent; border-top-style: none; border-right-color: transparent; border-left-style: none; border-left-color: transparent" type="text" />
            </td>
	        <td style="display:none">
		        <input id="PostName" name="PostName" style="border-bottom-style: none; border-bottom-color: transparent; border-right-style: none; border-top-color: transparent; border-top-style: none; border-right-color: transparent; border-left-style: none; border-left-color: transparent" type="text" />
            </td>
	        <td>
		        <input id="PhoneNo" name="PhoneNo"  style="border-bottom-style: none; border-bottom-color: transparent; border-right-style: none; border-top-color: transparent; border-top-style: none; border-right-color: transparent; border-left-style: none; border-left-color: transparent" type="text" />
            </td>
	        <td>
		        <input id="EMail" name="EMail" style="border-bottom-style: none; border-bottom-color: transparent; border-right-style: none; border-top-color: transparent; border-top-style: none; border-right-color: transparent; border-left-style: none; border-left-color: transparent" type="text" />
            </td>

        </tr>
    </table>
    </form>
</body>
</html>
